/* Copyright (C) 2014-2016 Dan Chapman <dpniel@ubuntu.com>

   This file is part of Dekko email client for Ubuntu Devices/

   This program is free software; you can redistribute it and/or
   modify it under the terms of the GNU General Public License as
   published by the Free Software Foundation; either version 2 of
   the License or (at your option) version 3

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef PS_POSTALSERVICEWORKER_H
#define PS_POSTALSERVICEWORKER_H

#include <QObject>
#include <QList>
#include <QHash>
#include <QSharedPointer>
#include "postalmessage.h"

namespace MessagingMenu {
class Source;
class Application;
class Message;
}
namespace Dekko
{
namespace Notifications
{

class PostalServiceWorker : public QObject
{
    Q_OBJECT
public:
    explicit PostalServiceWorker(QObject *parent = 0);

Q_SIGNALS:

public Q_SLOTS:
//    void sendPost(PostalMessage *post);
    void sendNotification(QSharedPointer<PostalMessage> notification);
    void sendErrorNotification(ErrorMessage *errorMsg);
    void clearPersistentMessage(QSharedPointer<PostalMessage> message);
    void removeAllSources(); // Removes all children messages as well. SHould be called when app becomes active
//    void setCount(int count);

//private slots:
//    void wasPostDeliveredToPostOffice(QDBusPendingCallWatcher *watcher);
//    void clearPersistentTags(QStringList &tags);
private slots:
    void handleSourceActivated(const QString &sourceId);
    void handleMessageActivated(const QString &msgId);
    void removeMessageFromMenu(const QString &srcId, const QString &msgId);

private:
    void notifySend(QSharedPointer<PostalMessage> notification);
    void appendToMsgMenu(QSharedPointer<PostalMessage> notification);
    void playSound();
    MessagingMenu::Application *m_mmApp;
    QList<MessagingMenu::Source *> m_sources;
    QHash<QString, QList<MessagingMenu::Message *> > m_messages;
    QHash<QString, QSharedPointer<PostalMessage> > m_msgMap;
    QString appId;
    QString pkgname;
    QString token;

};
}
}

#endif // PS_POSTALSERVICEWORKER_H
